const express = require("express")
const router = express.Router()
const { _GetSlider, _GetSingList, _GetSinger, _GetRankList, _GetSearchHot} = require('../api/get')
const { _PostSongList, _PostSingerDetail, _PostLyric, _PostMusicInfo, _PostRankMusic, _PostSearchList} = require("../api/post")

router.get('/', (req, res) => {
  res.send("QQ音乐接口大全:<a>轮播图地址</a>")
})

router.get('/slider', (req, res) => {
  _GetSlider((d) => res.send(d))
})

router.get('/singList', (req, res) => {
  _GetSingList((d) => res.json(d) )
})

router.get('/singer', (req, res) => {
  _GetSinger((d) => res.send(d))
})

router.get('/ranklist',(req ,res) => {
  _GetRankList( (d) => res.json(d))
})

router.get('/searchHot', (req, res) => {
  _GetSearchHot((d) => res.json(d))
})

router.post('/singerDetail', (req, res) => {
  _PostSingerDetail(req.body.id, (d) => res.send(d))
})

router.post('/music', (req, res) => {
  _PostMusicInfo(req.body.id, (d) => res.send(d))
})

router.post('/lyric', (req, res) => {
  _PostLyric(req.body.id, (lyric) => {
    if (typeof lyric === 'string') {
      var reg = /^\w+\(({[^()]+})\)$/
      var matches = lyric.match(reg)
      if (matches) {
        lyric = JSON.parse(matches[1])
      }
    }
    res.json(lyric)
  })
})

router.post('/rankmusic',(req,res) => {
  _PostRankMusic(req.body.id, (d) => res.json(d))
})

router.post('/songlist', (req, res) => {
  _PostSongList(req.body.id, (d) => res.json(d))
})

router.post('/searchList', (req, res) => {
  _PostSearchList(req.body.query, req.body.zhida, req.body.page, req.body.perpage, (d) => res.json(d))
})

module.exports = router